package com.dianjing.dianqun.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dianjing.dianqun.common.ResponseData;
import com.dianjing.dianqun.model.DianPaiContentComment;
import com.dianjing.dianqun.model.Site;
import com.dianjing.dianqun.service.dianpai.DianPaiContentCommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * @date : 2017年11月3日
 * 
 * @author: baoyongtao
 * 
 * @see :
 * 
 */
@Controller
@RequestMapping("/comment/")
public class CommentController {
	@Autowired
	private DianPaiContentCommentService commentService;

	@RequestMapping("list")
	public String list(HttpServletRequest request, ModelMap model) {
		return "comment/list";
	}

	@RequestMapping("getCommnetList.json")
	@ResponseBody
	public Object getCommnetList(HttpServletRequest request, @RequestParam(defaultValue = "0") Integer pageNum,
			@RequestParam(defaultValue = "20") Integer pageSize) {
		PageHelper.startPage(pageNum, pageSize, true);
		PageInfo<DianPaiContentComment> page = new PageInfo<DianPaiContentComment>(commentService.findAllComment());
		return new ResponseData(ResponseData.STATUS_OK, "请求成功", page);
	}
	@RequestMapping("chckedAllOrId")
	@ResponseBody
	public Object chckedAllOrId(HttpServletRequest request,@RequestParam(value="id" , required=false) Integer id) {
		if(id!=null) {
			DianPaiContentComment comment = commentService.selectByPrimaryKey(id);
			if(comment!=null) {
				comment.setIsChecked(2);
				commentService.updateByPrimaryKey(comment);
				return new ResponseData(ResponseData.STATUS_OK, "请求成功", null);
			}
		}
		commentService.chckedAll();
		return new ResponseData(ResponseData.STATUS_OK, "请求成功", null);
	}

}
